package com.billsharing.server;


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AddFriend
 */
@WebServlet("/DeleteFriend")
public class DeleteFriend extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = response.getWriter();
		AndroidResponse andres = new AndroidResponse();
		int userid = andres.uid2;
		String fndid1, email, phone,userid1;
		String delfnd_email = request.getParameter("fndemail");
		int uid=Integer.parseInt(request.getParameter("uid"));
		String result = null;
		Connection conn = null;

		try {
			Class.forName ("com.mysql.jdbc.Driver").newInstance();

			conn = DriverManager.getConnection("jdbc:mysql://csdb.csc.villanova.edu/auppalap","auppalap","fL00355727");
			System.out.println("Database connection established for Delete friend class");
			Statement s = conn.createStatement();
			Statement s1=conn.createStatement(); 
			Statement s2 = conn.createStatement();
			 int i=s1.executeUpdate("delete from Friend where userid="+uid+" AND fndemail='"+delfnd_email+"'");
			 System.out.println("Inside of while loop");
			 if(i>0)
	     	   {
				  System.out.println("Row deleted");
	     		   result="true1";
	     		  
	     	   }
	     	   else
	     	   {
	     		   result="false1";
	     	   }
			 
	     	   
			  
			System.out.println(result);
			out.print(result);

		} 
		
		catch (Exception e)
        {
            out.print (e.toString());

        }
		
		finally 
		{
			if (conn != null)
            {
                try
                {
                	 
                    conn.close ();
                    
                }
                catch (Exception e) { /* ignore close errors */ }
            }
		}
	}
}
